//
//  ErrorCell.m
//  OrderFood
//
//  Created by leilei on 2018/11/15.
//  Copyright © 2018年 zhiyuan. All rights reserved.
//

#import "ErrorCell.h"

@implementation ErrorCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubViews1];
    }
    return self;
}


-(void)setupSubViews1 {
    
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    self.quhuoLb = [UILabel new];
    self.qh_distanceLb = [UILabel new];
    self.qh_timeLb = [UILabel new];
    
    self.qh_storeLb = [UILabel new];
    self.qh_addressLb = [UILabel new];
    
    self.lineView = [UIView new];
    
    self.songhuoLb = [UILabel new];
    self.sh_distanceLb = [UILabel new];
    self.sh_timeLb = [UILabel new];
    
    self.sh_addressLb = [UILabel new];
    self.sh_addressLb1 = [UILabel new];
    
    
    
    self.quhuoLb.font = FONT(13);
    self.quhuoLb.textColor = themeTextColor;
    self.quhuoLb.textAlignment = NSTextAlignmentCenter;
    self.quhuoLb.text = @"取货";
    self.qh_distanceLb.font = FONT(13);
    self.qh_distanceLb.textColor = themeTextColor;
    self.qh_distanceLb.textAlignment = NSTextAlignmentCenter;
    self.qh_distanceLb.text = @"计算中...";
    self.qh_timeLb.font = FONT(13);
    self.qh_timeLb.textColor = BLACKCOLOR;
    self.qh_timeLb.textAlignment = NSTextAlignmentCenter;
    self.qh_timeLb.text = @"计算中...";
    
    self.lineView.backgroundColor = GRAYCOLOR;
    
    self.songhuoLb.font = FONT(13);
    self.songhuoLb.textColor = themeTextColor;
    self.songhuoLb.textAlignment = NSTextAlignmentCenter;
    self.songhuoLb.text = @"送货";
    self.sh_distanceLb.font = FONT(13);
    self.sh_distanceLb.textColor = themeTextColor;
    self.sh_distanceLb.textAlignment = NSTextAlignmentCenter;
    self.sh_distanceLb.text = @"计算中...";
    self.sh_timeLb.font = FONT(13);
    self.sh_timeLb.textColor = BLACKCOLOR;
    self.sh_timeLb.textAlignment = NSTextAlignmentCenter;
    self.sh_timeLb.text = @"计算中...";
    
    self.qh_storeLb.font = FONT(15);
    self.qh_addressLb.font = FONT(14);
    self.qh_addressLb.textColor = themeTextColor;
    self.qh_addressLb.numberOfLines = 0;
    
    self.sh_addressLb.font = FONT(15);
    self.sh_addressLb.numberOfLines = 0;
    
    
    self.sh_addressLb1.font = FONT(14);
    self.sh_addressLb1.textColor = themeTextColor;
    
    
    ////头部佣金的约束
    UIView *topView = [UIView new];
    topView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left);
        make.right.mas_equalTo(self.contentView.mas_right);
        make.top.mas_equalTo(self.contentView.mas_top);
        make.height.mas_equalTo(TargetWidth(41));
    }];
    
    
    
    self.orderMoneyLb = [UILabel new];
    self.orderMoneyLb.textColor = themeColor;
    self.orderMoneyLb.font = FONT(18);
    [topView addSubview:self.orderMoneyLb];
    [self.orderMoneyLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(topView.mas_left).offset(15);
        make.right.mas_equalTo(topView.mas_right).offset(-15);
        make.top.mas_equalTo(topView.mas_top);
        make.bottom.mas_equalTo(topView.bottom);
    }];
    
    UIView *lineView1 = [[UIView alloc]initWithFrame:CGRectMake(0, TargetWidth(41)-1, SCREEN_WIDTH, 1)];
    lineView1.backgroundColor = RGBColor(241, 241, 241);
    [topView addSubview:lineView1];
    
    
    UIView *remakView = [UIView new];
    remakView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:remakView];
    [remakView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left);
        make.right.mas_equalTo(self.contentView.mas_right);
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
        make.top.mas_equalTo(self.contentView.mas_top).offset(TargetWidth(41)+TargetWidth(189));
    }];
    
    
//    for (NSInteger index = 0; index < 2; index ++) {
        UIView *lineView2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
        lineView2.backgroundColor = RGBColor(241, 241, 241);
        [remakView addSubview:lineView2];
//        if (index == 1) {
//            [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.left.mas_equalTo(self.contentView.mas_left);
//                make.right.mas_equalTo(self.contentView.mas_right);
//                make.bottom.mas_equalTo(remakView.mas_bottom).offset(-1);
//                make.height.mas_equalTo(1);
//            }];
//        }
//    }
    
    
    
    self.orderRemarkLb = [UILabel new];
    self.orderRemarkLb.textColor = BLACKCOLOR;
    self.orderRemarkLb.font = FONT(15);
    self.orderRemarkLb.numberOfLines = 0;
    [remakView addSubview:self.orderRemarkLb];
    [self.orderRemarkLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(remakView.mas_left).offset(TargetWidth(17));
        make.right.mas_equalTo(remakView.mas_right).offset(-TargetWidth(17));
        make.bottom.mas_equalTo(remakView.mas_bottom).offset(-TargetWidth(15));
        make.top.mas_equalTo(remakView.mas_top).offset(TargetWidth(15));
    }];
    
    
    UIView *backView = [UIView new];
    backView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left);
        make.right.mas_equalTo(self.contentView.mas_right);
        make.top.mas_equalTo(self.orderMoneyLb.mas_bottom);
        make.bottom.mas_equalTo(remakView.mas_top);
    }];
    
    [backView addSubview:self.quhuoLb];
//    [backView addSubview:self.qh_distanceLb];
//    [backView addSubview:self.qh_timeLb];
    [backView addSubview:self.lineView];
    [backView addSubview:self.songhuoLb];
//    [backView addSubview:self.sh_distanceLb];
//    [backView addSubview:self.sh_timeLb];
    [backView addSubview:self.sh_addressLb];
    [backView addSubview:self.sh_addressLb1];
    [backView addSubview:self.qh_storeLb];
    [backView addSubview:self.qh_addressLb];
    
    
    
    ////取货lable约束
    [self.quhuoLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(backView.mas_left).offset(TargetWidth(10));
        make.top.mas_equalTo(backView.mas_top).offset(TargetWidth(23));
        make.height.mas_equalTo(TargetWidth(46));
        make.width.mas_equalTo(TargetWidth(80));
    }];
    
//    ////去店的距离约束
//    [self.qh_distanceLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(backView.mas_left).offset(TargetWidth(10));
//        make.top.mas_equalTo(self.quhuoLb.mas_bottom).offset(TargetWidth(5));
//        make.height.mas_equalTo(TargetWidth(10));
//        make.width.mas_equalTo(TargetWidth(80));
//    }];
//
//    ////去店的时间约束
//    [self.qh_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(backView.mas_left).offset(TargetWidth(10));
//        make.top.mas_equalTo(self.qh_distanceLb.mas_bottom).offset(TargetWidth(5));
//        make.height.mas_equalTo(TargetWidth(13));
//        make.width.mas_equalTo(TargetWidth(80));
//    }];
    
    /////拨打商家电话
    
    UIButton *btnCallStore = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImageView *imageViewStore = [UIImageView new];
    imageViewStore.image = [UIImage imageNamed:@"dianhua"];
    [btnCallStore addSubview:imageViewStore];
    btnCallStore.tag = 155;
    [btnCallStore addTarget:self action:@selector(btnCall:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:btnCallStore];
    [btnCallStore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(backView.mas_right).offset(-(40+TargetWidth(20)));
        make.right.mas_equalTo(backView.mas_right);
        make.top.mas_equalTo(self.quhuoLb.mas_top);
//        make.bottom.mas_equalTo(self.qh_timeLb.mas_bottom);
        make.bottom.mas_equalTo(self.quhuoLb.mas_bottom);
    }];
    [imageViewStore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(btnCallStore.mas_left).offset(13);
        make.right.mas_equalTo(btnCallStore.mas_right).offset(-27);
        make.top.mas_equalTo((TargetWidth(46)-TargetWidth(20))/2);
        make.height.mas_equalTo(TargetWidth(20));
        make.width.mas_equalTo(TargetWidth(20));
    }];
    
    
    
    ////门店名约束
    [self.qh_storeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.quhuoLb.mas_right).offset(TargetWidth(10));
        make.top.mas_equalTo(self.quhuoLb.mas_top).offset(-TargetWidth(3));
        make.height.mas_equalTo(TargetWidth(16));
        make.right.mas_equalTo(btnCallStore.mas_left);
    }];
    
    ////门店地址约束
    [self.qh_addressLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.quhuoLb.mas_right).offset(TargetWidth(10));
        make.top.mas_equalTo(self.qh_storeLb.mas_bottom).offset(TargetWidth(3));
//        make.bottom.mas_equalTo(self.qh_timeLb.mas_bottom).offset(TargetWidth(3));
        make.bottom.mas_equalTo(self.quhuoLb.mas_bottom).offset(TargetWidth(3));

        make.right.mas_equalTo(btnCallStore.mas_left);
    }];
    
    
    
    
    
    
    ////黑线的约束
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(backView.mas_left).offset(TargetWidth(50));
//        make.top.mas_equalTo(self.qh_timeLb.mas_bottom).offset(TargetWidth(2));
        make.top.mas_equalTo(self.quhuoLb.mas_bottom).offset(TargetWidth(2));

        make.height.mas_equalTo(TargetWidth(49));
        make.width.mas_equalTo(1.5);
    }];
    
    ////送货lable约束
    [self.songhuoLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(backView.mas_left).offset(TargetWidth(10));
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(TargetWidth(3));
        make.height.mas_equalTo(TargetWidth(46));
        make.width.mas_equalTo(TargetWidth(80));
    }];
    
//    ////去用户的距离约束
//    [self.sh_distanceLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(backView.left).offset(TargetWidth(10));
//        make.top.mas_equalTo(self.songhuoLb.mas_bottom).offset(TargetWidth(5));
//        make.height.mas_equalTo(TargetWidth(10));
//        make.width.mas_equalTo(TargetWidth(80));
//    }];
//
//    ////去用户的时间约束
//    [self.sh_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(backView.left).offset(TargetWidth(10));
//        make.top.mas_equalTo(self.sh_distanceLb.mas_bottom).offset(TargetWidth(5));
//        make.height.mas_equalTo(TargetWidth(13));
//        make.width.mas_equalTo(TargetWidth(80));
//    }];
    
    
    /////拨打用户电话
    UIButton *btnCallUser = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImageView *imageViewUser = [UIImageView new];
    imageViewUser.image = [UIImage imageNamed:@"dianhua"];
    [btnCallUser addSubview:imageViewUser];
    btnCallUser.tag = 156;
    [btnCallUser addTarget:self action:@selector(btnCall:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:btnCallUser];
    [btnCallUser mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(backView.mas_right).offset(-(40+TargetWidth(20)));
        make.right.mas_equalTo(backView.mas_right);
        make.top.mas_equalTo(self.songhuoLb.mas_top);
//        make.bottom.mas_equalTo(self.sh_timeLb.mas_bottom);
        make.bottom.mas_equalTo(self.songhuoLb.mas_bottom);
    }];
    [imageViewUser mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(btnCallUser.mas_left).offset(13);
        make.right.mas_equalTo(btnCallUser.mas_right).offset(-27);
        make.top.mas_equalTo((TargetWidth(46)-TargetWidth(20))/2);
        make.height.mas_equalTo(TargetWidth(20));
        make.width.mas_equalTo(TargetWidth(20));
    }];
    
    
    ////用户地址约束 小地址 电话名字
    [self.sh_addressLb1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.songhuoLb.mas_right).offset(TargetWidth(10));
        //        make.top.mas_equalTo(self.songhuoLb.mas_top);
//        make.bottom.mas_equalTo(self.sh_timeLb.mas_bottom);
        make.bottom.mas_equalTo(self.songhuoLb.mas_bottom);
        make.right.mas_equalTo(btnCallUser.mas_left);
        make.height.mas_equalTo(TargetWidth(13));
    }];
    ////用户地址约束 大地址
    [self.sh_addressLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.songhuoLb.mas_right).offset(TargetWidth(10));
        make.top.mas_equalTo(self.songhuoLb.mas_top).offset(-TargetWidth(3));
        make.bottom.mas_equalTo(self.sh_addressLb1.mas_top).offset(-TargetWidth(3));
        make.right.mas_equalTo(btnCallUser.mas_left);
    }];
    
    
    
    
}

-(void)btnCall:(UIButton *)sender {
    if (sender.tag == 155) {////拨打商家电话
        if ([self.deleateE respondsToSelector:@selector(errorCellDidCall:isUser:)]) {
            [self.deleateE errorCellDidCall:self isUser:NO];
        }
    }else {////拨打用户电话
        if ([self.deleateE respondsToSelector:@selector(errorCellDidCall:isUser:)]) {
            [self.deleateE errorCellDidCall:self isUser:YES];
        }
    }
}


-(void)setOrderModel:(OrderModel *)orderModel {
    _orderModel = orderModel;
    self.orderMoneyLb.text = [NSString stringWithFormat:@"佣金：%@", orderModel.deliveryCommission];
    self.qh_storeLb.text = orderModel.shop.name;
    self.qh_addressLb.text = orderModel.shop.address;
    self.sh_addressLb.text = [NSString stringWithFormat:@"%@%@", orderModel.user.region, orderModel.user.detail];
    self.sh_addressLb1.text = [NSString stringWithFormat:@"%@ %@ %@", orderModel.user.consignee, [orderModel.user.sex isEqualToString:@"1"]?@"女士":@"先生", orderModel.user.phone];
    
    
    if(_orderModel.remark.length == 0) {
        self.orderRemarkLb.text =  @"暂无备注";
    }else {
        self.orderRemarkLb.text = [NSString stringWithFormat:@"备注：%@", _orderModel.remark];
    }

}




- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
